#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include<signal.h>

#define MSGKEY 2222

struct mybuf {
	long mtype;
	char text[100];
};

int main(){
		int qid;
		
		// 创建消息队列 获得qid
		qid = msgget(MSGKEY, IPC_CREAT | 0666);
			if(qid==-1){
		perror("Failed in calling msgget");
		return 0;
	}
	int i=0;
	printf("Receiver is on!\n");
		while(i<10){
			
			struct mybuf buf;
			// qid	存放的地址  消息大小  接受类型  采取的行动
			printf("message %d:\t", i);
			msgrcv(qid, &buf, sizeof(buf.text), 0, MSG_NOERROR);//接收消息
			
			printf("%s\n", buf.text);
			i++;
		}
		
	return 0;
}
	
